Programming Problems by Bradley Green

Programming Problems by Bradley Green

Author:Bradley Green
Language: eng
Format: epub
Tags: programming, computer, software, c, interviewing, interviewing experts, software development, interviewing skills, algorithms, software testing interview, interviewing ebook, interviewing book, software engineering, data structures, programming langauge, programming reference, software reference books, c11
Publisher: Bradley Green


Listing 6.1: A Simple Hash Function

size_t hash(const std::string& str) {

if (str.empty()) return 0;

return str[0] - 'a';

}

This function is deterministic and extremely efficient, its range is limited to only 26 values and hence many strings will hash to the same value. Further, the corpus of English words it is not uniformly distributed across these 26 values. An examination of the words in the Gutenberg library shows that 17% of the words start with t, nearly 12% of words start with the letter a but only 0.05% of words start with z.

To overcome these two problems, we add complexity to the calculation of the hash value.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.